﻿using FriendlyURL.Web.Domain.Abstract;
using Ninject;
using Ninject.Modules;

namespace FriendlyURL.Web.Domain.Impl
{
    /// <summary>
    /// This class is used as a container for dependency injection throughout the entire application
    /// </summary>
    public class DIFactory
    {
        public static IKernel _kernel = null;
        /// <summary>
        /// Method used to create a single instance of Ninject's IKernel
        /// </summary>
        /// <returns>IKernel</returns>
        public static IKernel GetNinjectFactory()
        {
            if (_kernel == null)
            {
                var modules = new INinjectModule[]
                {
                    new ServiceModule()
                };

                _kernel = new StandardKernel(modules);
            }
            return _kernel;
        }

        /// <summary>
        /// Method used as a service locator for the ICache interface
        /// </summary>
        /// <returns></returns>
        public static ICache CreateCacheType()
        {
            return _kernel.Get<ICache>();
        }

        /// <summary>
        /// Method used as a service locator for the IConfiguration interface
        /// </summary>
        /// <returns></returns>
        public static IConfiguration CreateConfigurationType()
        {
            return _kernel.Get<IConfiguration>();
        }


        /// <summary>
        /// Method used as a service locator for the IMessageHandler interface
        /// </summary>
        /// <returns></returns>
        public static IMessageHandler CreateMessageHandlerType()
        {
            return _kernel.Get<IMessageHandler>();
        }

        /// <summary>
        /// Method used as a service locator for the IUserCookie interface
        /// </summary>
        /// <returns></returns>
        public static IUserCookie CreateUserCookieType()
        {
            return _kernel.Get<IUserCookie>();
        }

        /// <summary>
        /// Method used as a service locator for the IWebContext interface
        /// </summary>
        /// <returns></returns>
        public static IWebContext CreateWebContextType()
        {
            return _kernel.Get<IWebContext>();
        }
    }
}
